package com.tsc.design.responsibilityMode.example;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chentl
 * @Date: 2025/09/17/17:32
 * @Description:
 */
public abstract class Logger {

    protected LogLevel level;//日志级别
    protected Logger nextLogger;//下一个日志处理器

    public Logger(LogLevel level) {
        this.level = level;
    }

    public void setNextLogger(Logger nextLogger) {
        this.nextLogger = nextLogger;
    }

    public void logMessage(LogLevel level, String message) {
        if (this.level.ordinal() <= level.ordinal()) {
            write(message);
        }
        if (nextLogger != null) {
            nextLogger.logMessage(level, message);
        }
    }

    abstract protected void write(String message);

    public static LogLevel getLogLevel(String level) {
        return LogLevel.valueOf(level);
    }
}
